<template>
  <div class="update-gender">
    <van-picker
      show-toolbar
      title="标题"
      :columns="columns"
      @cancel="$emit('close')"
      @confirm="onConfirm"  
      :default-index="value"
      @change="onPickerChange"
    />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'

export default {
  name: 'UpdateGender',
  components: {},
  props: {
  value:{
    type:Number,
    required:true
  }
  },
  data () {
    return {
     columns: ['男', '女', ],
     localGender:this.value
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
 
    async onConfirm() {
      try {
        const localGender= this.localGender
        await updateUserProfile({
          gender:localGender
        })
        // 更新视图，
        //注意新用法:子组件在传值的时候，选用input，如this.$emit(‘input’,val)，在父组件直接用v-model绑定，就可以获取到
        this.$emit('input', localGender)
        // 关闭弹层
        this.$emit('close')
        // 提示成功
        this.$toast.success('更新成功')
      } catch (error) {
        this.$toast('更新失败')
      }
    },
    //用法看vant picker组件
    onPickerChange (picker, value, index) {
      this.localGender=index
    },
    
     
  }
}
</script>

<style scoped lang="less"></style>
